const Classify = require("../model/classify.model.js");
let Goods = require("../model/goods.model");
class ClassifyService {
  async crateClassify(obj) {
    const res = await Classify.create(obj);

    return res;
  }
  async delClassify(id) {
    await Goods.destroy({ where: { classify_id: id } });
    return await Classify.destroy({ where: { id } });
  }
  async update(obj) {
    await Classify.update(
      { classify_name: obj.classify_name },
      {
        where: {
          id: obj.id,
        },
      }
    );
  }
  async findClassifyAll() {
    const { rows, count } = await Classify.findAndCountAll();

    return {
      count,
      list: rows,
    };
  }
}
module.exports = new ClassifyService();
